package com.abocode.aichat.server.modules.protocol;


import com.abocode.aichat.server.modules.AbstractModule;
import com.abocode.aichat.server.modules.AbstractModule;

/**
 * Created by franky-14.
 */
public class AuthModule extends AbstractModule {

    @Override
    public boolean isChannelReady() {
        return false;
    }


//    private final AuthModuleHandler authModuleHandler = new AuthModuleHandler();

    @Override
    public String namespace() {
        return "auth";
    }

    @Override
    public String version() {
        return "1.0";
    }

//
//    class AuthModuleHandler implements ModuleHandler {
//        @Override
//        public Replies execute(ChannelWrapper channelWrapper, Stanza stanza) {
////            if ("domain".equals(module)) {
////                return get(channelWrapper, stanza);
////            }
//            if ("auth".equals(stanza.module())) {
//                return auth(channelWrapper, stanza);
//            } else {
//                throw new RuntimeException("");
//            }
//        }
//
//        public Replies auth(ChannelWrapper channelWrapper, Stanza stanza) {
//            Map body = stanza.body();
//            String uid = String.valueOf(body.get("uid"));
//            String os = String.valueOf(body.get("os"));
//            String token = String.valueOf(body.get("token"));
//            String presence = String.valueOf(body.get("presence"));
//            if (true) {
//                //todo token is ok
//            }
//            EntityImpl entity = EntityImpl.parse(uid + EntityImpl.CHAR_AT + getServerRuntimeContext().getDomain() + EntityImpl.CHAR_SLASH + os);
//            entity.setPresence(presence);
//            getServerRuntimeContext().getProtocolChannelRegistry().registerEntity(channelWrapper.getChannel(), entity);
//            Replies replies = new Replies();
//            Map map = new HashMap();
//            map.put("status", 200);
//            map.put("jid", entity.getFullName());
//            //todo jid return
//            Stanza _stanza = StanzaWrapper.wrapper(stanza, map);
//            replies.addReply(channelWrapper.getChannel(), _stanza);
//            return replies;
//        }
//
////        public Replies get(ChannelWrapper channelWrapper, Stanza stanza) {
////            Replies replies = new Replies();
////            Map map = new HashMap();
////            map.put("domain", getServerRuntimeContext().getDomain());
////            Stanza _stanza = StanzaWrapper.wrapper(stanza.id(), "auth", "domain", map);
////            replies.addReply(new Reply(channelWrapper.getChannel(), _stanza));
////            return replies;
////        }
//    }
//
//    @Override
//    public ModuleHandler moduleHandler() {
//        return authModuleHandler;
//    }
}
